<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: new_attributes_include.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

defined('_VALID_XTC') or die('Direct Access to this location is not allowed.');

require_once(DIR_FS_INC.'inc.get_tax_rate.php');
require_once(DIR_FS_INC.'inc.get_tax_class_id.php');
require(DIR_FS_CATALOG.DIR_WS_CLASSES.'class.price.php');
$price = new price(DEFAULT_CURRENCY,$_SESSION['customers_status']['customers_status_id']);
?>
<tr>
	<td class="pageHeading" colspan="8">
		<table class="table_pageHeading" width="100%" cellspacing="0" cellpadding="0">
			<tr>
				<td class="pageHeading">
					<?php echo $pageTitle; ?>
				</td>
			</tr>
		</table>
	</td>
</tr>
</table>
<?php 
	echo draw_form('submit_attributes', 'new_attributes.php', '', 'POST', 'enctype="multipart/form-data"')
	.draw_hidden_field('current_product_id', $_POST['current_product_id'])
	.draw_hidden_field('action', 'change');
?>
<table width="100%">
<?php
	require(DIR_WS_MODULES.'new_attributes_functions.php');
	$tempTextID = '1999043';

	$line = $db->db_query("SELECT
								*
							FROM
								".TABLE_PRODUCTS_OPTIONS."
							WHERE
								products_options_id
							LIKE
								'%'
							AND
								language_id = '".$_SESSION['languages_id']."'");

	if ($line->_numOfRows) {
	while(!$line->EOF) {
		echo '	<tr class="dataTableHeadingRow">';
		echo '		<td class="dataTableHeadingContent">
						<strong>'.$line->fields['products_options_name'].'</strong>
					</td>';
		echo '		<td class="dataTableHeadingContent"><strong>'.SORT_ORDER.'</strong></td>';
		echo '		<td class="dataTableHeadingContent"><strong>'.ATTR_MODEL.'</strong></td>';
		echo '		<td class="dataTableHeadingContent"><strong>'.ATTR_STOCK.'</strong></td>';
		echo '		<td class="dataTableHeadingContent"><strong>'.ATTR_SHOW_STOCK.'</strong></td>';
		echo '		<td class="dataTableHeadingContent" align="right"><strong>'.ATTR_PREFIXWEIGHT.'</strong></td>';
		echo '		<td class="dataTableHeadingContent"><strong>'.ATTR_WEIGHT.'</strong></td>';
		echo '		<td class="dataTableHeadingContent"><strong>'.ATTR_SHOW_WEIGHT.'</strong></td>';
		echo '		<td class="dataTableHeadingContent" align="right"><strong>'.ATTR_PREFIXPRICE.'</strong></td>';
		echo '		<td class="dataTableHeadingContent"><strong>'.ATTR_PRICE.'</strong></td>';
		echo '	</tr>';
		
		$get_tpl = $db->db_query("SELECT 
										options_view_type 
									FROM 
										".TABLE_PRODUCTS_ATTRIBUTES." 
									WHERE 
										products_id = '".$_POST['current_product_id']."' 
									AND 
										options_id = '".$line->fields['products_options_id']."'
									LIMIT 1");

		echo '	<tr class="attributes-even">
					<td colspan="10">
						Ansicht: 
						<select name="options_view_type_'.$line->fields['products_options_id'].'" style="width:auto">
							<option> -- wählen sie -- </option>
							<option value="s"'.($get_tpl->fields['options_view_type'] == 's' ? ' selected="selected"':'').'>Selection</option>
							<option value="d"'.($get_tpl->fields['options_view_type'] == 'd' ? ' selected="selected"':'').'>Dropdown</option>
						</select>
					</td>
				</tr>';
		
		$line_2 = $db->db_query("SELECT
									*
								FROM
									".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS."
								WHERE
									products_options_id = '".$line->fields['products_options_id']."'
								ORDER BY
									products_options_values_id DESC");
		
		if ($line_2->_numOfRows) {
			$i = '0';
			while (!$line_2->EOF) {
				$i++;
				$rowClass = rowClass($i);
				$current_value_id = $line_2->fields['products_options_values_id'];
				$isSelected = checkAttribute($current_value_id, $_POST['current_product_id'], $line->fields['products_options_id']);
				if ($isSelected)
					$checked = ' checked=""';
				else
					$checked = '';
				
				$line_3 = $db->db_query("SELECT
											*
										FROM
											".TABLE_PRODUCTS_OPTIONS_VALUES."
										WHERE
											products_options_values_id = '".$current_value_id."'
										AND
											language_id = '".$_SESSION['languages_id']."'");
				while(!$line_3->EOF) {
					$getStatus = $db->db_query("SELECT 
													attributes_stock_status,
													options_values_weight_status 
												FROM 
													".TABLE_PRODUCTS_ATTRIBUTES." 
												WHERE 
													products_id = '".$_POST['current_product_id']."' 
												AND 
													options_values_id = '".$current_value_id."' ");
			
					if($getStatus->fields['attributes_stock_status'] == '1')
						$Check_stock_status = ' checked=""';
					else
						$Check_stock_status = '';
					
					$current_value_name = $line_3->fields['products_options_values_name'];
					echo '<tr class="'.$rowClass.'">';
					echo '	<td class="main">';
					echo '		<input type="checkbox" name="optionValues[]" value="'.$current_value_id.'"'.$checked." /> ".$current_value_name;
					echo '	</td>';
					echo '	<td class="main" align="left">
								<input style="text-align:center" type="text" name="'.$current_value_id.'_sortorder" value="'.$sortorder.'" size="4" />
							</td>';
					echo '	<td class="main" align="left">
								<input type="text" name="'.$current_value_id.'_model" value="'.$attribute_value_model.'" size="15" />
							</td>';
					echo '	<td class="main" align="left">
								<input type="text" name="'.$current_value_id.'_stock" value="'.$attribute_value_stock.'" size="4" />
							</td>';
					
					echo '	<td class="main" align="center">
								<input type="checkbox" name="'.$current_value_id.'_stock_status" value="1"'.($getStatus->fields['attributes_stock_status'] == '1' ? ' checked=""' :'').' />
							</td>';		
					
					echo '	<td class="main" align="right">
								<select style="width:45px" name="'.$current_value_id.'_weight_prefix">
									<option value="+"'.$posCheck_weight.'>+</option>
									<option value="-"'.$negCheck_weight.'>-</option>
								</select>
							</td>';
					echo '	<td class="main" align="left">
								<input type="text" name="'.$current_value_id.'_weight" value="'.$attribute_value_weight.'" size="10">
							</td>';
					echo '	<td class="main" align="center">
								<input type="checkbox" name="'.$current_value_id.'_weigth_status" value="1"'.($getStatus->fields['options_values_weight_status'] == '1' ? ' checked=""' :'').' />
							</td>';	
					if (PRICE_IS_BRUTTO=='true'){
						$attribute_value_price_calculate = $price->format(round($attribute_value_price*((100+(get_tax_rate(get_tax_class_id($_POST['current_product_id']))))/100), PRICE_PRECISION),false);
					} else
						$attribute_value_price_calculate = $price->format($attribute_value_price, false);
					
					echo '	<td class="main" align="right">
								<select style="width:45px" name="'.$current_value_id.'_prefix">
									<option value="+"'.$posCheck.'>+</option>
									<option value="-"'.$negCheck.'>-</option>
								</select>
							</td>';
					echo '	<td class="main" align="left">';
								if (PRICE_IS_BRUTTO == 'true')
									echo 'Brutto:';
					echo '			<input type="text" name="'.$current_value_id.'_price" value="'.$attribute_value_price_calculate.'" size="5">';
								if (PRICE_IS_BRUTTO == 'true')
									echo ' '.TEXT_NETTO .'<strong>'.$price->format(round($attribute_value_price,PRICE_PRECISION), true).'</strong>';
					echo '	</td>';
					echo '</tr>';
					if(strtoupper($current_product_option_name) == 'DOWNLOADS') {
						echo '<tr class="'.$rowClass.'">';
					
						echo '	<td colspan="2">
									'.DL_FILE.'<br/><input type="file" name="'.$current_value_id.'_upload_file" />
								</td>';
						echo '	<td colspan="2">
									'.DL_CHOOSE.'<br />'.draw_pull_down_menu($current_value_id.'_download_file', getDownloads(), $attribute_value_download_filename, '').'
								</td>';
						echo '	<td colspan="2">
									'.DL_COUNT.'<br /><input type="text" name="'.$current_value_id.'_download_count" value="'.$attribute_value_download_count.'">
								</td>';
						echo '	<td colspan="4">
									'.DL_EXPIRE.'<br /><input type="text" name="'.$current_value_id.'_download_expire" value="'.$attribute_value_download_expire.'">
								</td>';
						echo '</tr>';
					}
					$line_3->MoveNext();
				}
				if ($i == $matches2 ) 
					$i = '0';
				$line_2->MoveNext();
			}
			echo '<tr><td colspan="10" style="height:4px">&nbsp;</td></tr>';
		} else {
		echo '<tr>';
		echo '<td class="main" align="center" colspan="10"><em>'.NO_VALUE.'</em></td>';
		echo '</tr>';
		}
		$line->MoveNext();
	}
}
?>
<tr>
	<td colspan="10" class="main"><br />
	<?php
		echo button(BUTTON_SAVE).'&nbsp;';
		echo '<a href="'.href_link('new_attributes.php', '', 'SSL').'" class="button">'.BUTTON_CANCEL.'</a>';
	?>
	</td>
</tr>
</table>
</form>